home *** CD-ROM | disk | FTP | other *** search
/ PC Player 2004 May / pc player 2004-05.iso / Demos / FarCry / Data1.cab / _2C07AC817B1543D9A86F2F6CEE7FDA42 < prev    next >
Encoding:
Text File  |  2004-01-06  |  5.0 KB  |  146 lines

  1. -- Questions;
  2. -- Whats does 'FTB' mean?
  3. -- This script does not make much sense, TotalBreathHoldTime is fine, but BreathFadeTime and
  4. -- BreathHoldTime, BreathScale, BreathOutTime etc... AND what kind of 'time' are these values?
  5. -- (minutes, seconds, milisceonds?? they seem to be inconsistant)
  6. --
  7. -- How the sniper should work....
  8. -- Zoom-in, adjust with the MWheel what zoom factor, scope has some shake to it (which is 
  9. --   adjustable). Holding your breath will will steady the scope over an adjustable time.
  10. --   You can hold your breath for an adjustable time frame.
  11. -- If you hold your breath too long your loose your zoom (exit zoom mode)
  12. -- If you hold your breath too long the scope fades to black
  13. -- If you shoot you loose your Zoom (exit zoom mode)
  14. -- When you exit Zoom mode your zoom factor is remeber
  15. -- adjustable values should be in seconds or miliseconds (please comment :])
  16. --
  17. -- Tig
  18.  
  19. FTBSniping = {
  20.     SwayMultiplier = 0.0,        -- decrease factor of swaying
  21.     NormalMinSway = 0,
  22.     NormalMaxSway = 0,
  23.     SwayFreq = 0.2,                        -- the amount of change in the sway wobble
  24.     PrevSway = 0,
  25.     TotalBreathHoldTime = 15,    -- time you can hold the breath
  26.     BreathFadeTime = 2,        -- time in which the view changes (during breath in)
  27.     BreathHoldTime = 0,
  28.     ReleasingBreath = nil,
  29.     BreathScale = 2,        -- the maximum factor of breathing when we change fom breath in to -out
  30.     BreathOutTime = 0,
  31.     TotalBreathOutTime = 1.3,        -- time needed to breath out
  32.     BreathInSnd = Sound:LoadSound("sounds/player/breathin.wav"),
  33.     BreathOutSnd = Sound:LoadSound("sounds/player/breathout.wav"),
  34.     BreathBlurImg = System:LoadImage("Textures/Hud/BreathBlur.tga"),
  35.     ExtraZoom = 0.0,
  36. }
  37.  
  38. function FTBSniping:OnInit()
  39.     self.BreathHold = 0;
  40.     Sound:SetSoundLoop( FTBSniping.BreathInSnd, 0 );
  41.     Sound:SetSoundLoop( FTBSniping.BreathOutSnd, 0 );
  42.     Sound:SetSoundVolume( FTBSniping.BreathInSnd, 25 );
  43.     Sound:SetSoundVolume( FTBSniping.BreathOutSnd, 25 );
  44. end
  45.  
  46. function FTBSniping:OnActivate()
  47.     self.SwayMultiplier = 0.0125;
  48.     self.NormalMinSway = ZoomView.MinSway;
  49.     self.NormalMaxSway = ZoomView.MaxSway;
  50.     self.PrevSway = ZoomView.Sway;
  51. end
  52.  
  53. function FTBSniping:OnUpdate()
  54.     local States = ZoomView;
  55.     local stats = _localplayer.cnt;
  56.  
  57.     if ( stats.holding_breath and ( stats.moving == nil ) and ( self.ReleasingBreath == nil ) ) then        
  58.         -- we've pressed the button, are not moving and we dont breath out so hold the breath...
  59.         if ( States.Sway == States.MinSway ) then        
  60.             -- you can only hold the breath if you're not out-of-breath =)
  61.             if ( self.BreathHoldTime == 0 ) then        
  62.                 -- we just started to breath in, so play sound and set params
  63.                 Sound:PlaySound( FTBSniping.BreathInSnd );
  64.                 FTBSniping.OnActivate(self);
  65.                 stats:SetSwayFreq(self.SwayFreq);
  66.                 self.NormalMinSway = States.MinSway;
  67.                 self.NormalMaxSway = States.MaxSway;
  68.                 self.PrevSway = States.Sway;
  69.                 --States.MinSway = States.Sway * self.SwayMultiplier;
  70.             end
  71.         end
  72.         self.BreathHoldTime = self.BreathHoldTime + _frametime;
  73.     else
  74.         self:BreathRelease();
  75.     end
  76.  
  77.     if (stats.holding_breath) then
  78.         -- Make crosshair smoothly come to rest
  79.         local Inverse = 1.0 - self.SwayMultiplier;
  80.         local ScaledSwayMul = 1.0 - Inverse  * (States.Sway) * min(1.0, self.BreathHoldTime / self.BreathFadeTime);
  81.  
  82.         ZoomView.AddZoom = 1 - (ScaledSwayMul * 1);
  83.         --ZoomView.AddZoom = 0;
  84.  
  85.         ScaledSwayMul = max(ScaledSwayMul, self.SwayMultiplier);
  86.         States.MinSway = States.Sway * ScaledSwayMul;
  87.         if (States.MinSway < 0.5 * self.NormalMinSway) then
  88.             States.MinSway = 0.5 * self.NormalMinSway;
  89.         end
  90.     end
  91.  
  92.     if ( self.ReleasingBreath ) then
  93.         --tig 
  94.         --want to kill the zoom if the player holds their breath too long
  95.         ZoomView.AddZoom = 0;
  96.  
  97.         self.BreathOutTime = self.BreathOutTime + System:GetFrameTime();
  98.         if ( self.BreathOutTime >= self.TotalBreathOutTime ) then
  99.             self.ReleasingBreath = nil;
  100.             self.BreathOutTime = 0;
  101.         end
  102.     end
  103. end
  104.  
  105. function FTBSniping:OnFire()
  106.     --tig
  107.     --want to kill the zoom here!!
  108.     self:BreathRelease();
  109.     --ClientStuff.vlayers:DeactivateLayer("WeaponScope");
  110.     
  111. end
  112.  
  113. function FTBSniping:OnEnhanceHUD()
  114.     if ( ( self.BreathHoldTime > 0 ) ) then
  115.         local mul = self.BreathHoldTime / self.BreathFadeTime;
  116.         if ( mul > 1 ) then
  117.             mul = 1;
  118.         end
  119.         System:DrawImageColor( FTBSniping.BreathBlurImg, 0, 0, 800, 600, 4, 1, 1, 1, mul );
  120.         self.BreathScale = mul;
  121.     end
  122.     if ( self.ReleasingBreath ) then
  123.         local mul = ( 1 - ( self.BreathOutTime / self.TotalBreathOutTime ) ) * self.BreathScale;
  124.         System:DrawImageColor( FTBSniping.BreathBlurImg, 0, 0, 800, 600, 4, 1, 1, 1, mul );
  125.     end
  126. end
  127.  
  128. function FTBSniping:BreathRelease()
  129.     local States = ZoomView;
  130.  
  131.     if ( self.BreathHoldTime > 0 ) then        
  132.         -- still holding the breath, so breath out
  133.  
  134.         System:LogToConsole("--> Breathing Out !!!");
  135.         Sound:PlaySound( FTBSniping.BreathOutSnd );
  136.         self.BreathHoldTime = 0;
  137.         self.BreathOutTime = 0;
  138.         States.MinSway = self.NormalMinSway;
  139.         --States.MaxSway = self.PrevSway * 2;
  140.         --if ( States.MaxSway > 5 ) then
  141.         --    States.MaxSway = 5;
  142.         --end
  143.         --States.SwayInc = 1;
  144.         self.ReleasingBreath = 1;
  145.     end
  146. end